package com.quanyue.music.file.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Scope;
import com.quanyue.music.domain.constant.UserRole;
import com.quanyue.music.domain.entity.MusicTag;
import com.quanyue.music.file.service.MusicTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "音乐标签")
@Scope(role = UserRole.MANAGER)
@RestController
@RequestMapping("/api")
public class MusicTagController {
    @Autowired
    private MusicTagService musicTagService;

    @ApiOperation(value = "添加标签")
    @PostMapping(value = "/fm/tag/add", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> add(@RequestBody MusicTag musicTag) {
        musicTagService.add(musicTag);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "更新标签信息")
    @PostMapping(value = "/fm/tag/update", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> update(@RequestBody MusicTag musicTag) {
        musicTagService.update(musicTag);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "删除分类")
    @DeleteMapping(value = "/fm/tag/delete", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<Boolean> delete(@RequestParam("id") String id) {
        musicTagService.delete(id);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "获取标签列表")
    @GetMapping(value = "/fm/tag/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult<List<MusicTag>> findList() {
        return ServiceResult.success(musicTagService.findList());
    }
}
